var config = require('config.js');
App({
  onLaunch: function () {
    //隐藏系统tabbar
    // wx.hideTabBar();
    //获取设备信息
    this.getSystemInfo();
  },
  request: function request({ url, method, data, success, complete, fail }) {
    // console.log(url)
    if (url == 'api/wechat/sendCodeTixian' || url == 'api/wechat/sendCode'){

    }else{
      wx.showLoading({ title: "页面加载中" })
    }
    url = config.apiUrl + url
    // console.log("请求链接：" + url)
    var method = method ? method : "GET"
    var data = data ? data : {}
    var success = success ? success : function () { }
    var complete = complete ? complete : function () { }
    var fail = fail ? fail : function () { }
    // console.log(data)
    // console.log(wx.getStorageSync("cookie"))
    wx.request({
      url: url,
      data: data,
      method: method,
      header: {
        'content-type': 'application/json',
        'cookie': wx.getStorageSync("cookie")
      },
      success: (res) => {
        console.log(res)
        wx.hideLoading()
        console.log(res.data.code)
        if (res.data.code == 20000) {
          wx.removeStorageSync('cookie')
          wx.navigateTo({
            url: '/pages/start/index',
          })
        }
        if (res.data.code == 20001) {
          wx.showToast({ title: "该账号已限制使用！", icon: "none", duration: 3000 });
        }
        success(res.data, res.header)
      },
      fail: function (res) {
        wx.hideLoading()
        wx.showToast({ title: "网络开小差了，请重新检查网络", icon: "none", duration: 3000 });
        fail(res);
      },
      complete: (res) => {
        complete(res)
      }
    })
  },
  getSystemInfo: function () {
    let t = this;
    wx.getSystemInfo({
      success: function (res) {
        t.globalData.systemInfo = res;
      }
    });
  },
  editTabbar: function () {
    let tabbar = this.globalData.tabBar;
    let currentPages = getCurrentPages();
    let _this = currentPages[currentPages.length - 1];
    let pagePath = _this.route;
    
    (pagePath.indexOf('/') != 0) && (pagePath = '/' + pagePath);


    // if(pagePath.indexOf('/') != 0){
    //   pagePath = '/' + pagePath;
    // } 
   
    for (let i in tabbar.list) {
      tabbar.list[i].selected = false;
      (tabbar.list[i].pagePath == pagePath) && (tabbar.list[i].selected = true);
    }
    _this.setData({
      tabbar: tabbar
    });
  },
  globalData: {
    systemInfo: null,//客户端设备信息
    userInfo: null,
    AlreadyJumpedLogin:false,
    tabBar: {
      "backgroundColor": "#ffffff",
      "color": "#888",
      "custom":true,
      "selectedColor": "#3cb672",
      "list": [
        {
          "pagePath": "/pages/index/index",
          "iconPath": "../images/icon_home.png",
          "selectedIconPath": "../images/icon_home_HL.png",
          "text": "首页"
        },
        {
          "pagePath": "/scan",
          "iconPath": "../images/icon3_20.png",
          "isSpecial": false,
          "text": "扫一扫"
        },
        {
          "pagePath": "/pages/personalCenter1/index",
          "iconPath": "../images/icon_mine.png",
          "selectedIconPath": "../images/icon_mine_HL.png",
          "text": "个人中心"
        }
      ]
    }
  }
})